/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AccueilApp.java
 *
 * Created on 22 mai 2010, 19:08:42
 */

package responsableDeStage;
import gestionDeStageDAO.MysqlConnect ;
import eleve.*;

import java.awt.Color;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Labassi Amine
 */
public class AccueilApp extends javax.swing.JFrame {

    Connection cnt = null ;
    /** Creates new form AccueilApp */
    public AccueilApp() {
        initComponents();
        this.setLocationRelativeTo(this.getParent());
        this.jPanelAccAppMain.setBackground(Color.LIGHT_GRAY);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelAccAppMain = new javax.swing.JPanel();
        jTextFieldAccAppLogin = new javax.swing.JTextField();
        jTextFieldAccAppMotPass = new javax.swing.JPasswordField();
        jComboBoxAccAppDomaine = new javax.swing.JComboBox();
        jButtonAccAppConnect = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaAccAppComm = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ISTY - Application Gestion De Stage");
        setResizable(false);

        jPanelAccAppMain.setForeground(new java.awt.Color(255, 204, 204));

        jComboBoxAccAppDomaine.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Direction Ecole", "Responsable des stages", "Tuteur", "Elève" }));

        jButtonAccAppConnect.setText("Connection");
        jButtonAccAppConnect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAccAppConnectActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel1.setText("Login ");

        jLabel2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel2.setText("Mot de passe ");

        jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel3.setText("Domaine ");

        jTextAreaAccAppComm.setColumns(20);
        jTextAreaAccAppComm.setEditable(false);
        jTextAreaAccAppComm.setRows(5);
        jScrollPane1.setViewportView(jTextAreaAccAppComm);

        javax.swing.GroupLayout jPanelAccAppMainLayout = new javax.swing.GroupLayout(jPanelAccAppMain);
        jPanelAccAppMain.setLayout(jPanelAccAppMainLayout);
        jPanelAccAppMainLayout.setHorizontalGroup(
            jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelAccAppMainLayout.createSequentialGroup()
                .addGap(51, 51, 51)
                .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addGap(36, 36, 36)
                .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jTextFieldAccAppLogin, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                    .addComponent(jTextFieldAccAppMotPass, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                    .addComponent(jComboBoxAccAppDomaine, 0, 198, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jButtonAccAppConnect, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(61, 61, 61))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 578, Short.MAX_VALUE)
        );
        jPanelAccAppMainLayout.setVerticalGroup(
            jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelAccAppMainLayout.createSequentialGroup()
                .addContainerGap(156, Short.MAX_VALUE)
                .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelAccAppMainLayout.createSequentialGroup()
                        .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldAccAppLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldAccAppMotPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelAccAppMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBoxAccAppDomaine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)))
                    .addComponent(jButtonAccAppConnect))
                .addGap(45, 45, 45)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelAccAppMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelAccAppMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonAccAppConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAccAppConnectActionPerformed
        if ( jTextFieldAccAppLogin.getText().equals("respdestage") && !jTextFieldAccAppMotPass.getText().equals("") && jComboBoxAccAppDomaine.getSelectedItem().toString().equals("Responsable des stages")){
            MysqlConnect mysqlcnt = new MysqlConnect(jTextFieldAccAppLogin.getText(), jTextFieldAccAppMotPass.getText());
            try {
                cnt = mysqlcnt.connect();
                if(cnt != null) this.jTextAreaAccAppComm.setText("Succès authentification...\n");
                this.jTextAreaAccAppComm.setText(this.jTextAreaAccAppComm.getText()+"Mise à jour de la base de données...\n");
                this.jTextAreaAccAppComm.setText(this.jTextAreaAccAppComm.getText()+"Lancement de l'application...\n");
                EcranRespDeStage ERDS = new EcranRespDeStage((com.mysql.jdbc.Connection) cnt);
                this.setVisible(false);
                ERDS.setVisible(true);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
               this.jTextAreaAccAppComm.setText("Erreur d'authentification...\n");
               this.jTextFieldAccAppLogin.setText("");
               this.jTextFieldAccAppMotPass.setText("");
            }
        } else if (!jTextFieldAccAppLogin.getText().equals("") && !jTextFieldAccAppMotPass.getText().equals("") && jComboBoxAccAppDomaine.getSelectedItem().toString().equals("Elève")){
            MysqlConnect mysqlcnt = new MysqlConnect(jTextFieldAccAppLogin.getText(), jTextFieldAccAppMotPass.getText());
            try {
                cnt = mysqlcnt.connect();
                if(cnt != null) this.jTextAreaAccAppComm.setText("Succès authentification...\n");
                this.jTextAreaAccAppComm.setText(this.jTextAreaAccAppComm.getText()+"Mise à jour de la base de données...\n");
                this.jTextAreaAccAppComm.setText(this.jTextAreaAccAppComm.getText()+"Lancement de l'application...\n");
                EcranEleve EE = new EcranEleve((com.mysql.jdbc.Connection) cnt);
                this.setVisible(false);
                EE.setVisible(true);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(AccueilApp.class.getName()).log(Level.SEVERE, null, ex);
               this.jTextAreaAccAppComm.setText("Erreur d'authentification...\n");
               this.jTextFieldAccAppLogin.setText("");
               this.jTextFieldAccAppMotPass.setText("");
            }
        } else {
               this.jTextAreaAccAppComm.setText("Erreur d'authentification...\n");
               this.jTextFieldAccAppLogin.setText("");
               this.jTextFieldAccAppMotPass.setText("");
        }
        
    }//GEN-LAST:event_jButtonAccAppConnectActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAccAppConnect;
    private javax.swing.JComboBox jComboBoxAccAppDomaine;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanelAccAppMain;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextAreaAccAppComm;
    private javax.swing.JTextField jTextFieldAccAppLogin;
    private javax.swing.JTextField jTextFieldAccAppMotPass;
    // End of variables declaration//GEN-END:variables

}
